home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / computer vision recognition / rcinstall.exe / Disk1 / data1.cab / ASP_Pages / WebHelp / bsscnbar.js < prev    next >
Encoding:
JavaScript  |  2001-12-12  |  15.6 KB  |  516 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // RoboHELP« Navigator Bar for WebHelp
  3. // Copyright ⌐ 1999-2000 eHelp Corporation.  All rights reserved.
  4.  
  5. // Version= 4.30
  6. // patch 1
  7.  
  8. // Warning:  Do not modify this file.  It is generated by RoboHELP« and changes will be overwritten.
  9.  
  10. // This file is used to support Navigator bar in WebHelp
  11. // The main functions are Sync toc. Show or Hide Navigator Panel. 
  12.  
  13. // call onBsscNavHide() from bsscright frame.
  14. // Hide the bsscleft frame(Nav). and show the current topic.
  15.  
  16. // call onBsscNavShow() from any frame except bsscright.
  17. // Show the bsscleft frame(Nav). and show the current topic in the bsscright frame. and sync toc.
  18.  
  19. // call onBsscNavSync() from bsscright frame.
  20. // there will be two situation.
  21. // 1. Nav is visible.  Just Sync the toc.( show the Contents panel and highlight the related topic).
  22. // 2. Nav is invisible. First Show the Nav panel. and then Sync the toc.
  23.  
  24.  
  25. // onBsscNavSync(strRelHomePage) strRelHomePage is the Relative Path of the First Page, from the current page's view.
  26. // other function will be called by onContent(). do not call them directly.
  27.  
  28. // onBsscNavSync is modified from onContents() in SyncFromTopic.js. add support DHTML sync. 
  29.  
  30. // BsscNavHasNavFrame() determine the Nav frame exists or not
  31.  
  32.  
  33. var gbDHTML = false;
  34.  
  35. var strAgent   = navigator.userAgent.toLowerCase();
  36. var strVersion = navigator.appVersion.toLowerCase();
  37.  
  38. var gnVerMajor = parseInt(strVersion);
  39. var gnVerMinor = parseFloat(strVersion);
  40.  
  41. var gbNS     = ((strAgent.indexOf("mozilla") != -1) && ((strAgent.indexOf('spoofer') == -1) && (strAgent.indexOf('compatible') == -1)));
  42. var gbIE     = (strAgent.indexOf("msie") != -1);
  43. var gbOpera  = (strAgent.indexOf("opera") != -1);
  44. var gbHotJava= (strVersion.indexOf("hotjava") != -1);
  45.  
  46. var gbWin16   = ((strVersion.indexOf("win16") != -1) || (strVersion.indexOf("windows 3.1") != -1));
  47. var gbWindows = ((strAgent.indexOf("win") != -1) || (strAgent.indexOf("16bit") != -1));
  48. var gbMac     = (strAgent.indexOf("mac") != -1);
  49. var gbWebTV   = (strAgent.indexOf("webtv") != -1);
  50. var gbSunOS   = (strAgent.indexOf("sunos") != -1);
  51.  
  52. var gbNS2         = ((gbNS) && (gnVerMajor == 2));
  53. var gbNS3         = ((gbNS) && (gnVerMajor == 3));
  54. var gbNS4         = ((gbNS) && (gnVerMajor >= 4));
  55. var gbNS6         = ((gbNS) && (gnVerMajor >= 5));
  56. var gbIE4         = ((gbIE) && (gnVerMajor >= 4));
  57. var gbIE400          = (strAgent.indexOf("msie 4.0;") != -1);
  58. var gbIE3         = ((gbIE) && (gnVerMajor <= 3));
  59. var gbIE302before = ((gbIE3) && ((strAgent.indexOf("3.00") != -1)||(strAgent.indexOf("3.0a") != -1)||(strAgent.indexOf("3.0b")!=-1)||(strAgent.indexOf("3.01")!=-1))); 
  60.  
  61. var gbIE5      = ((gbIE4) && (strAgent.indexOf("msie 5") != -1));
  62.  
  63. var nViewFrameType = 2;  //1: DTHTML 2:Applet 3: HTML2 list
  64.  
  65. if (gbIE4 && gbDHTML) nViewFrameType = 1;
  66. if (gbIE4 && gbSunOS) nViewFrameType = 1;
  67.  
  68. if (gbWin16)          nViewFrameType = 3;
  69. if (gbIE3 && gbMac)   nViewFrameType = 3;
  70. if (gbNS2)            nViewFrameType = 3;
  71. if (gbNS3 && gbMac)   nViewFrameType = 3;
  72. if (gbOpera)          nViewFrameType = 3;
  73. if (gbHotJava)        nViewFrameType = 3;
  74. if (gbWebTV)          nViewFrameType = 3;
  75. if (gbIE302before)    nViewFrameType = 3;
  76.  
  77. if ((gbNS4) && (window.screen) && (window.screen.colorDepth == 4))
  78. {
  79.    nViewFrameType = 3;
  80. }
  81.  
  82. function BsscNavIsList() {
  83.     return (nViewFrameType == 3 || (gbIE4 && !gbIE5 && gbMac));
  84. }
  85.  
  86. var gbstrNavnAgent   = navigator.userAgent.toLowerCase();
  87.  
  88. var gbNavnNS    = false;
  89. var gbNavnIE    = false;
  90. gbNavnNS     = ((gbstrNavnAgent.indexOf("mozilla") != -1) && ((gbstrNavnAgent.indexOf('spoofer') == -1) && (gbstrNavnAgent.indexOf('compatible') == -1)));
  91. gbNavnIE        = (gbstrNavnAgent.indexOf("msie") != -1);
  92.  
  93. var gbstrAbsHomePageURL = "";
  94. var gbstrRelHomePageURL = "";
  95. var gbCurrentTopicURL   = "";
  96. var gHomePage = null;
  97.  
  98. function _bsscnBarEqualURL(strAbsHomePageURL, strCurrentURL)
  99. {
  100.     var strNormalstrAbsHomePageURL = strAbsHomePageURL.toLowerCase();
  101.     var strNormalstrCurrentURL = strCurrentURL.toLowerCase();
  102.  
  103.     strNormalstrAbsHomePageURL = _bsscnBarConvertToURLFormat(strNormalstrAbsHomePageURL);
  104.     strNormalstrCurrentURL = _bsscnBarConvertToURLFormat(strNormalstrCurrentURL);
  105.  
  106.     if (strNormalstrAbsHomePageURL == strNormalstrCurrentURL)
  107.         return true;
  108.     else 
  109.         return false;
  110. }
  111.  
  112. // change αßπ to %E0%E1%E3
  113. function _bsscnBarConvertToURLFormat(strURL)
  114. {
  115.     var strResURL = "";
  116.     var i = 0;
  117.     if (!gbNS4 && !gbIE4) return strURL;
  118.     for (i = 0; i < strURL.length; i ++)
  119.     {
  120.         var nCode = strURL.charCodeAt(i);
  121.         if (nCode > 127) {
  122.             strResURL += "%";
  123.             var strTemp = String.fromCharCode(HEXToCharCode(nCode/16), HEXToCharCode(nCode%16));
  124.             strResURL += strTemp
  125.         }
  126.         else 
  127.             strResURL += strURL.charAt(i);
  128.     }
  129.     if (strResURL.indexOf("file:/") == 0 && strResURL.indexOf("file:///") == -1) {
  130.         strResURL = strResURL.replace("file:/", "file:///");
  131.     }
  132.     return strResURL;
  133. }
  134.  
  135. function HEXToCharCode(n)
  136. {
  137.     if (n < 10) {
  138.         return '0'.charCodeAt(0) + n;
  139.     }
  140.     else if (n < 16) {
  141.         return 'A'.charCodeAt(0) + (n - 10);
  142.     }
  143.     else
  144.         return 0;
  145. }
  146.  
  147. function _bsscnBarGetStartPage(pwindow) {
  148.     var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  149.     var strCurrentURL = pwindow.document.URL;
  150.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  151.     var nEndPos  = strCurrentURL.indexOf('#');
  152.     if (nEndPos != -1) {
  153.         strCurrentURL = strCurrentURL.substring(0, nEndPos);
  154.     }
  155.     if (_bsscnBarEqualURL(strAbsHomePageURL, strCurrentURL)) {
  156.         return pwindow;
  157.     }
  158.     else {
  159.         if (pwindow.parent.frames.length != 0 && pwindow.parent != pwindow && pwindow.parent != null) 
  160.         {
  161.             gbCurrentTopicURL = strCurrentURL;
  162.             return _bsscnBarGetStartPage(pwindow.parent);
  163.         }
  164.         else 
  165.             if (typeof(pwindow.gbHomePage) != "undefined") 
  166.                 return pwindow;
  167.             else
  168.                 return null;
  169.  
  170.     }
  171. }
  172.  
  173. function _bsscnBarGetOutMostTopic(pwindow) {
  174.     var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  175.     var strCurrentURL = pwindow.document.URL;
  176.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  177.  
  178.     var strOutStartPage = pwindow.gbstrRelHomePageURL;
  179.     if (typeof(strOutStartPage) == "undefined") return null;
  180.  
  181.     var strOutAbsHomePageURL = _bsscnBarGetOutAbsHomePageURL(strCurrentURL, strOutStartPage);
  182.  
  183.     if (_bsscnBarEqualURL(strAbsHomePageURL, strOutAbsHomePageURL)) {
  184.         if (pwindow.parent.frames.length != 0 && pwindow.parent != pwindow && pwindow.parent != null) {
  185.             var pfind = _bsscnBarGetOutMostTopic(pwindow.parent);
  186.             if (pfind == null) {
  187.                 gbCurrentTopicURL = strCurrentURL;
  188.                 return pwindow;
  189.             }
  190.             else
  191.                 return pfind;
  192.         }
  193.         else  {
  194.             gbCurrentTopicURL = strCurrentURL;
  195.             return pwindow;
  196.         }
  197.     }
  198.     else
  199.         return null;
  200. }
  201.  
  202. function _bsscnBarGetOutAbsHomePageURL(strCurrentURL, strOutStartPage)
  203. {
  204.     var strRelHomePage = _bsscnBarReplaceSlash(strOutStartPage);
  205.     
  206.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  207.     
  208.     var strCurrentPath = _bsscnBarGetPath(strCurrentURL);
  209.     var strCurrentFile = _bsscnBarGetFileName(strCurrentURL);
  210.     
  211.     var strAbsHomePageURL = _bsscnBarGetAbsoluteHomePageURL(strRelHomePage, strCurrentPath);
  212.     
  213.     return strAbsHomePageURL;
  214. }
  215.  
  216. function BsscNavHasNavFrame()
  217. {
  218.     var bHomePage = false;
  219.     if (gHomePage == null)
  220.         gHomePage =     _bsscnBarGetStartPage(parent);    
  221.  
  222.     if (gHomePage != null)
  223.         bHomePage = true;
  224.     return bHomePage;
  225. }
  226.  
  227. // call onBsscNavHide() from bsscright frame.
  228. // Hide the bsscleft frame(Nav). and show the current topic.
  229. function onBsscNavHide()
  230. {
  231.     
  232.     if (BsscNavHasNavFrame()) {
  233.         var strCurrentURL = document.URL;
  234.         var OutTopic = _bsscnBarGetOutMostTopic(window);
  235.         if (OutTopic != null) {
  236.             if (gbCurrentTopicURL.length > 0) 
  237.                 strCurrentURL = gbCurrentTopicURL;
  238.         }
  239.         
  240.         if (strCurrentURL.toLowerCase().indexOf("file://") == 0) {
  241.             strCurrentURL = _bsscnBarReplaceSpecialChar(strCurrentURL);
  242.         }
  243.         if (gbNS6)
  244.             gHomePage.document.location = strCurrentURL;
  245.         else
  246.             gHomePage.document.location.replace(strCurrentURL);
  247.     }
  248. }
  249.  
  250. // call onBsscNavShow() from any frame except bsscright.
  251. // Show the bsscleft frame(Nav). and show the current topic in the bsscright frame. and sync toc.
  252. function onBsscNavShow()
  253. {
  254.     if (!BsscNavHasNavFrame()) {
  255.  
  256.         var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  257.         var strAbsHomePagePath = _bsscnBarGetPath(strAbsHomePageURL);
  258.  
  259.         strAbsHomePagePath = strAbsHomePagePath + "/";
  260.     
  261.         var strCurrentURL = document.URL;
  262.         strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  263.  
  264.         var OutTopic = _bsscnBarGetOutMostTopic(window);
  265.         if (OutTopic != null)
  266.             if (gbCurrentTopicURL.length > 0) 
  267.                 strCurrentURL = gbCurrentTopicURL;
  268.  
  269.         var startpos  = strCurrentURL.indexOf(strAbsHomePagePath);
  270.         if (startpos != -1) {
  271.             strRelativeURL = strCurrentURL.substring(startpos + strAbsHomePagePath.length, strCurrentURL.length);
  272.             if (strAbsHomePageURL.toLowerCase().indexOf("file://") == 0) 
  273.                 strAbsHomePageURL = _bsscnBarReplaceSpecialChar(strAbsHomePageURL);
  274.             if (OutTopic != null) {
  275.                 if (gbIE400) // ie 4.00 can not recognize the bookmark locally.
  276.                     OutTopic.location.replace(strAbsHomePageURL);
  277.                 else
  278.                     if (gbNS6)
  279.                         OutTopic.location = strAbsHomePageURL+"#" + strRelativeURL;
  280.                     else
  281.                         OutTopic.location.replace(strAbsHomePageURL+"#" + strRelativeURL);
  282.             }
  283.         }
  284.     }
  285. }
  286.  
  287. function _bsscnBarGetAbsHomePageURL()
  288. {
  289.     if ( gbstrAbsHomePageURL.length > 0) return gbstrAbsHomePageURL;
  290.  
  291.     var strRelHomePage = _bsscnBarReplaceSlash(gbstrRelHomePageURL);
  292.     
  293.     var strCurrentURL = document.URL;
  294.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  295.     
  296.     var strCurrentPath = _bsscnBarGetPath(strCurrentURL);
  297.     var strCurrentFile = _bsscnBarGetFileName(strCurrentURL);
  298.     
  299.     gbstrAbsHomePageURL = _bsscnBarGetAbsoluteHomePageURL(strRelHomePage, strCurrentPath);
  300.     
  301.     return gbstrAbsHomePageURL;
  302. }
  303.  
  304. function onBsscAutoSync()
  305. {
  306.     var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  307.     var strAbsHomePagePath = _bsscnBarGetPath(strAbsHomePageURL);
  308.  
  309.     strAbsHomePagePath = strAbsHomePagePath + "/";
  310.     
  311.     var strCurrentURL = document.URL;
  312.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  313.     
  314.     var startpos  = strCurrentURL.indexOf(strAbsHomePagePath);
  315.     
  316.     if (startpos != -1) {
  317.         strRelativeURL = strCurrentURL.substring(startpos + strAbsHomePagePath.length, strCurrentURL.length);
  318.         if (BsscNavHasNavFrame()) {
  319.             if(gbNavnIE) {// IE
  320.                 if (gHomePage.document.frames[0].document.applets.length > 0) {
  321.                     if (typeof(gHomePage.document.frames[0].document.applets["webhelp"]) != "undefined") {
  322.                         if (!gbIE4 || !gbWindows || gHomePage.document.frames[0].gbLoading != "unknown") 
  323.                             gHomePage.document.frames[0].document.applets["webhelp"].Command("AutoSync", strRelativeURL);
  324.                     }
  325.                 }
  326.                 else {
  327.                     // probably DHTML
  328.                     if (typeof(gHomePage.document.frames[0].document.frames["Tabs"]) != "undefined") {
  329.                         var tabFrame = gHomePage.document.frames[0].document.frames["Tabs"];
  330.                         _bsscnBarAutoSync(strRelativeURL);
  331.                     } 
  332.                     else { // it must be list
  333.                     }
  334.                 }
  335.             }
  336.             else { // Probably Netscape.
  337.                 if (gHomePage.frames[0].document.applets.length > 0) {
  338.                     if (typeof(gHomePage.frames[0].document.applets["webhelp"]) != "undefined") {
  339.                         gHomePage.frames[0].document.applets["webhelp"].Command("AutoSync", strRelativeURL);
  340.                     }
  341.                 }
  342.                 else {
  343.                     // probably DHTML
  344.                     if (typeof(gHomePage.document.frames[0].document.frames["Tabs"]) != "undefined") {
  345.                         _bsscnBarAutoSync(strRelativeURL);
  346.                     }
  347.                     else { // it must be list
  348.                     }
  349.                 }
  350.             }
  351.         }
  352.     }
  353. }
  354.  
  355. function onBsscNavSync()
  356. {
  357.     var strAbsHomePageURL = _bsscnBarGetAbsHomePageURL();
  358.     var strAbsHomePagePath = _bsscnBarGetPath(strAbsHomePageURL);
  359.  
  360.     strAbsHomePagePath = strAbsHomePagePath + "/";
  361.     
  362.     var strCurrentURL = document.URL;
  363.     strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
  364.     
  365.     var startpos  = strCurrentURL.indexOf(strAbsHomePagePath);
  366.     
  367.     if (startpos != -1) {
  368.         strRelativeURL = strCurrentURL.substring(startpos + strAbsHomePagePath.length, strCurrentURL.length);
  369.         if (BsscNavHasNavFrame()) {
  370.             if(gbNavnIE) {// IE
  371.                 if (gHomePage.document.frames[0].document.applets.length > 0) {
  372.                     if (typeof(gHomePage.document.frames[0].document.applets["webhelp"]) != "undefined") {
  373.                         gHomePage.document.frames[0].document.applets["webhelp"].Command("SyncToc", strRelativeURL);
  374.                     }
  375.                 }
  376.                 else {
  377.                     // probably DHTML
  378.                     if (typeof(gHomePage.document.frames[0].document.frames["Tabs"]) != "undefined") {
  379.                         var tabFrame = gHomePage.document.frames[0].document.frames["Tabs"];
  380.                         _bsscnBarSelectTOC(strRelativeURL);
  381.                     } 
  382.                     else { // it must be list
  383.                     }
  384.                 }
  385.             }
  386.             else { // Probably Netscape.
  387.                 if (gHomePage.frames[0].document.applets.length > 0) {
  388.                     if (typeof(gHomePage.frames[0].document.applets["webhelp"]) != "undefined") {
  389.                         gHomePage.frames[0].document.applets["webhelp"].Command("SyncToc", strRelativeURL);
  390.                     }
  391.                 }
  392.                 else {
  393.                     // probably DHTML
  394.                     if (typeof(gHomePage.document.frames[0].document.frames["Tabs"]) != "undefined") {
  395.                         _bsscnBarSelectTOC(strRelativeURL);
  396.                     }
  397.                     else { // it must be list
  398.                     }
  399.                 }
  400.             }
  401.         }
  402.         else
  403.             //location.replace(strAbsHomePageURL+"#" + strRelativeURL);
  404.             onBsscNavShow();
  405.     }
  406. }
  407.  
  408.  
  409. // replace %20 to ' '
  410. function _bsscnBarReplaceSpecialChar(strURL)
  411. {    
  412.     var strReplacedURL = "";
  413.     for (i = 0; i < strURL.length; i ++ )
  414.     {
  415.         if (strURL.charAt(i) == '%') {
  416.             if (strURL.substring(i + 1, i + 3) == "20") {
  417.                 strReplacedURL = strReplacedURL + " ";
  418.                 i += 2;
  419.             }
  420.             else
  421.                 strReplacedURL = strReplacedURL + strURL.charAt(i);
  422.         }
  423.         else
  424.             strReplacedURL = strReplacedURL + strURL.charAt(i);
  425.     }
  426.     return strReplacedURL;
  427. }
  428.  
  429.  
  430. // replace \\ to /
  431. function _bsscnBarReplaceSlash(strURL)
  432. {    
  433.     var strReplacedURL = "";
  434.     for (i = 0; i < strURL.length; i ++ )
  435.     {
  436.         if (strURL.charAt(i) == '\\') 
  437.             strReplacedURL = strReplacedURL + "/"
  438.         else
  439.             strReplacedURL = strReplacedURL + strURL.charAt(i);
  440.     }
  441.     return strReplacedURL;
  442. }
  443.  
  444. // generate absolute URL for the first page.
  445. function _bsscnBarGetAbsoluteHomePageURL(strRelHomePage, strCurrentPath)
  446. {
  447.     if (strCurrentPath.charAt(strCurrentPath.length - 1) == '/') 
  448.         strCurrentPath = strCurrentPath.substring(0, strCurrentPath.length -1);
  449.     for (;;) {
  450.         upDirPos = strRelHomePage.indexOf("../")
  451.         if (upDirPos == 0) {
  452.             DirPos = strCurrentPath.lastIndexOf("/")
  453.             if (DirPos != -1) {
  454.             strCurrentPath = strCurrentPath.substring(0, DirPos)
  455.             }
  456.             strRelHomePage = strRelHomePage.substring(3, strRelHomePage.length);
  457.         }
  458.         if (upDirPos != 0) break;
  459.     }
  460.     return strCurrentPath + "/" + strRelHomePage;
  461. }
  462.  
  463. function _bsscnBarGetPath(strURL)
  464. {
  465.     pathpos = strURL.lastIndexOf("/");
  466.     if (pathpos > 0)
  467.         return strURL.substring(0, pathpos);
  468.     else 
  469.         return "";
  470. }
  471.  
  472. function _bsscnBarGetFileName(strURL)
  473. {
  474.     pathpos = strURL.lastIndexOf("/");
  475.     if (pathpos > 0)
  476.         return strURL.substring(pathpos + 1, strURL.length);
  477.     else
  478.         return strURL;
  479. }
  480.  
  481. function _bsscnBarGetTabFrame()
  482. {
  483.     if (gHomePage == null) return null;
  484.     if(gbNavnIE) {// IE
  485.         return gHomePage.document.frames[0];
  486.     }
  487.     else { // Netscape
  488.         return gHomePage.frames[0];
  489.     }
  490. }
  491.  
  492. function _bsscnBarAutoSync(strRelativeURL)
  493. {
  494.     var TabFrame = _bsscnBarGetTabFrame();
  495.     if ("function" == typeof(TabFrame.autosync))
  496.         TabFrame.autosync(strRelativeURL);
  497. }
  498.  
  499.  
  500.  
  501. function _bsscnBarSelectTOC(strRelativeURL)
  502. {
  503.     var TabFrame = _bsscnBarGetTabFrame();
  504.     if ("function" == typeof(TabFrame.syncToc))
  505.         TabFrame.syncToc(strRelativeURL);
  506. }
  507.  
  508.  
  509. function _bsscnBarOnError(message)
  510. {
  511.     if(-1 != message.indexOf("denied") 
  512.         || -1 != message.indexOf("Object required"))
  513.      return true;
  514. }
  515.  
  516. onerror = _bsscnBarOnError;